# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        黄周云  
# Name:         test14
# Description:  列表的基本操作
# Author:       ASUS
# Date:         2019/1/22
#-------------------------------------------------------------------------------

#列表元素赋值
s= ["Bill","Mike","John"]
s[0]="Mary"
print(s)                       #['Mary', 'Mike', 'John']
s[-1]="cindy"
print(s)                       #['Mary', 'Mike', 'cindy']
# s[3]="蜘蛛侠"
# s[-4]="hello"
# print(s)             #超出索引范围，抛出异常

#删除列表元素
numbers=[1,2,3,4,5,6,7,8]
print(numbers)              #[1, 2, 4, 5, 6, 7, 8]
del numbers[2]

# 分片赋值
names=[]
names[:]=["mary","bill"]
print(names)                 #['mary', 'bill'],可以赋值空列表
s=["hello","world","year"]
s[:]=["a","b","c"]
print(s)                    #['a', 'b', 'c']，忽略开始索引和结束索引，可以改变整个列表
s=["hello","world","year"]
s[1:]=["a","b","c"]
print(s)                    #['hello', 'a', 'b', 'c']
s=["hello","world","year"]
s[1:8]=["a","b","c"]
print(s)                    #['hello', 'a', 'b', 'c']
s=["hello","world","year"]
s[1:1]=["a","b","c"]
print(s)                    #['hello', 'a', 'b', 'c', 'world', 'year']，在索引0和1之间插入新列表
s=["hello","world","year"]
s[1:2]=["a","b","c"]
print(s)                    #['hello', 'a', 'b', 'c', 'year']
s=["hello","world","year"]
s[1:3]=["a","b","c"]
print(s)                    #['hello', 'a', 'b', 'c']
s=["hello","world","year"]
s[1:2]=[]
print(s)                   #['hello', 'year'],删除一些列表元素


